package config;


import bean.Student;
import constants.Constant;

public class Public {
    //根据id自动分配寝室
    public static void distribution(Student stuInfo) {
        Integer stuId = stuInfo.getStuId();
        //先确保id在操作返回内
        stuId %= Constant.COUNT;
        if(stuId==0) stuId=Constant.COUNT;
        //计算在哪个楼栋哪层
        Integer count= stuId/Constant.LEVEL;
        Integer remain = stuId%Constant.LEVEL;
        if(remain>0) count++;
        //计算寝室号
        Integer dor = (stuId-(count-1)*480)/Constant.DOR;
        Integer remain2 = (stuId-(count-1)*480)%Constant.DOR;
        if(remain2>0) dor++;

        int tmp = count;
        if(count%5==0){
            count = count/5;
        } else{
            count = count/5+1;
        }

        if(tmp%5 ==0) {
            dor = (5*100)+dor;
        }else {
            dor = (tmp%5)*100+dor;
        }
        Integer bed = remain2==0?6:remain2;
        stuInfo.setBuildId(count);
        stuInfo.setDormitory(dor);
        stuInfo.setBed(bed);
        Integer remain3 = stuId%2400;
        Integer sex=0;
        if(remain3 > 0) {
             sex = ((stuId/2400)+1)%2==0?2:1;
        }else {
            sex = ((stuId/2400))%2==0?2:1;
        }

        stuInfo.setSex(sex);

    }
}
